using System;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Modules.NEWS.Controls
{
    public partial class ItemManager : YAFPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hlAddNew.NavigateUrl = string.Format("~/Modules/NEWS/Pages/ItemEdit.aspx?tabindex={0}&mid={1}&itemid=0", this.TabIndex, this.ModuleID);
            }
        }

        protected void gvItems_PageIndexChanged(object sender, EventArgs e)
        {
            gvItems.SelectedIndex = -1;
        }

        protected void cbStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvItems.SelectedIndex = -1;
            gvItems.Columns[gvItems.Columns.Count - 3].Visible = cbStatus.SelectedValue != "Published";            
        }

        
        protected void gvItems_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Approve")
            {
                //Components.Item.Approve(Convert.ToInt32(gvItems.SelectedValue));
                gvItems.DataBind();
                gvItems.SelectedIndex = -1;
            }
            else if (e.CommandName == "Edit")
            {
                string url = string.Format("~/Modules/NEWS/Pages/ItemEdit.aspx?tabindex={0}&mid={1}&itemid={2}", this.TabIndex, this.ModuleID, e.CommandArgument);
                Response.Redirect(url);
            }
        }

        protected void hfModuleID_Init(object sender, EventArgs e)
        {
            hfModuleID.Value = this.ModuleID.ToString();
        }
    }
}